// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;

namespace SnapObjects.Data.MySql
{
    internal class MySqlStatementFactory : SqlStatementFactory
    {
        public MySqlStatementFactory(ISqlGenerationHelper helper, ITypeMapper mapper)
            : base(helper, mapper)
        {
        }

        public override ISqlBuilderParser GetBuilderParser(SqlStatementType statementType)
        {
            switch (statementType)
            {
                case SqlStatementType.Select:
                {
                    return new MySqlQueryBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.SqlRaw:
                {
                    return new MySqlRawBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Insert:
                {
                    return new MySqlInsertBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Update:
                {
                    return new MySqlUpdateBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Delete:
                {
                    return new MySqlDeleteBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Procedure:
                {
                    return new MySqlProcedureBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Condition:
                {
                    return new MySqlConditionBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Function:
                {
                    return new MySqlFunctionBuilderParser(this, _helper, _mapper);
                }
                default:
                {
                    throw new NotSupportedException(statementType.ToString());
                }
            }
        }

        public override ISqlStatementGenerator GetSqlGenerator(SqlStatementType statementType)
        {
            ISqlStatementGenerator generator;

            switch (statementType)
            {
                case SqlStatementType.Select:
                {
                    generator = new MySqlSelectStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Insert:
                {
                    generator = new MySqlInsertStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Update:
                {
                    generator = new MySqlUpdateStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Delete:
                {
                    generator = new MySqlDeleteStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Procedure:
                {
                    generator = new MySqlProcedureStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Condition:
                {
                    generator = new MySqlConditionStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.SqlRaw:
                {
                    generator = new MySqlSqlRawStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Function:
                {
                    generator = new MySqlFunctionStatementGenerator(this, _helper, _mapper);
                }
                break;
                default:
                {
                    throw new NotSupportedException(statementType.ToString());
                }
            }

            return generator;
        }

        public override ISqlStatementParser GetSqlParser(SqlStatementType statementType)
        {
            ISqlStatementParser parser;

            switch (statementType)
            {
                case SqlStatementType.Select:
                {
                    parser = new MySqlSelectStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Delete:
                {
                    parser = new MySqlDeleteStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Update:
                {
                    parser = new MySqlUpdateStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Insert:
                {
                    parser = new MySqlInsertStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Procedure:
                {
                    parser = new MySqlProcedureStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.SqlRaw:
                {
                    parser = new MySqlSqlRawStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Function:
                {
                    parser = new MySqlFunctionStatementParser(this, _helper);
                }
                break;
                default:
                {
                    throw new NotSupportedException(statementType.ToString());
                }
            }

            return parser;
        }
    }
}
